﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;

namespace NotebookS2
{
    public partial class M_EXPENSE : RibbonForm
    {
        public M_EXPENSE()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }

        private void M_EXPENSE_Load(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (btnAdd.Text != "Update")
            {
                ExpenseManager oManager = new ExpenseManager();
                ExpenseUnit oUnit = new ExpenseUnit();

                oManager.ConnectionString = this.ConnectionString;
                oManager.Open();

                oUnit.ExpenseCode = txtExpenseCode.Text;
                oUnit.ExpenseName = txtExpenseName.Text;
                oUnit.GLAccountEntry = txtGLAccount.Text;


                txtExpenseCode.Properties.ReadOnly = true;
                oManager.AddExpense(oUnit);
                oManager.Close();

                btnAdd.Text = "Update";
            }
            else
            {
                ExpenseManager oManager = new ExpenseManager();
                ExpenseUnit oUnit = new ExpenseUnit();

                oManager.ConnectionString = this.ConnectionString;
                oManager.Open();

                oUnit.ExpenseCode = txtExpenseCode.Text;
                oUnit.ExpenseName = txtExpenseName.Text;
                oUnit.GLAccountEntry = txtGLAccount.Text;


                txtExpenseCode.Properties.ReadOnly = true;
                oManager.UpdateExpense(oUnit);
                oManager.Close();

                btnAdd.Text = "Update";
            }

        }

        private void txtExpenseCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            FND_EXPENSE oForm = new FND_EXPENSE();

            oForm.ConnectionString = this.ConnectionString;
            oForm.ShowDialog();

            if (oForm.SelectedExpenseCode != null)
            {
                txtExpenseCode.Text = oForm.SelectedExpenseCode;
                txtExpenseName.Text = oForm.SelectedExpenseName;
                txtGLAccount.Text = oForm.SelectedGLAccount;

                txtExpenseCode.Properties.ReadOnly = true;

                btnAdd.Text = "Update";
            }
        }
    }
}
